package casebill

import (
	"encoding/json"
	"strconv"
	"time"
)

type CaseBill struct {
	Boxes      []string `json:"boxes"`
	DeviceId   string   `json:"device_id"`
	Operator   int      `json:"operator"`
	CreateTime int64    `json:"create_time"`
}

func (c *CaseBill) ArgsToCaseBill(args []string) error {
	err := json.Unmarshal([]byte(args[0]), &(c.Boxes))
	if err != nil {
		return err
	}
	if err != nil {
		return err
	}
	c.DeviceId = args[1]
	c.Operator, err = strconv.Atoi(args[2])
	if err != nil {
		return err
	}
	createTime, err := time.Parse("2006-01-02 15:04:05", args[3])
	if err != nil {
		return err
	}
	c.CreateTime = createTime.Unix()
	return nil
}
